package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbDictMap;
import com.ruoyi.system.service.ITbDictMapService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 字典映射表Controller
 * 
 * @author 唐冰倩
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/system/map")
public class TbDictMapController extends BaseController
{
    @Autowired
    private ITbDictMapService tbDictMapService;

    /**
     * 查询字典映射表列表
     */
    @PreAuthorize("@ss.hasPermi('system:map:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDictMap tbDictMap)
    {
        startPage();
        List<TbDictMap> list = tbDictMapService.selectTbDictMapList(tbDictMap);
        return getDataTable(list);
    }

    /**
     * 导出字典映射表列表
     */
    @PreAuthorize("@ss.hasPermi('system:map:export')")
    @Log(title = "字典映射表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDictMap tbDictMap)
    {
        List<TbDictMap> list = tbDictMapService.selectTbDictMapList(tbDictMap);
        ExcelUtil<TbDictMap> util = new ExcelUtil<TbDictMap>(TbDictMap.class);
        util.exportExcel(response, list, "字典映射表数据");
    }

    /**
     * 获取字典映射表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:map:query')")
    @GetMapping(value = "/{mapId}")
    public AjaxResult getInfo(@PathVariable("mapId") String mapId)
    {
        return success(tbDictMapService.selectTbDictMapByMapId(mapId));
    }

    /**
     * 新增字典映射表
     */
    @PreAuthorize("@ss.hasPermi('system:map:add')")
    @Log(title = "字典映射表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDictMap tbDictMap)
    {
        return toAjax(tbDictMapService.insertTbDictMap(tbDictMap));
    }

    /**
     * 修改字典映射表
     */
    @PreAuthorize("@ss.hasPermi('system:map:edit')")
    @Log(title = "字典映射表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDictMap tbDictMap)
    {
        return toAjax(tbDictMapService.updateTbDictMap(tbDictMap));
    }

    /**
     * 删除字典映射表
     */
    @PreAuthorize("@ss.hasPermi('system:map:remove')")
    @Log(title = "字典映射表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mapIds}")
    public AjaxResult remove(@PathVariable String[] mapIds)
    {
        return toAjax(tbDictMapService.deleteTbDictMapByMapIds(mapIds));
    }
}
